package ph.gov.marikina.mcsmtms.rest.webservices.client;

import java.net.HttpURLConnection;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;

public class BasicSecureSimpleClientHttpRequestFactory extends SecureSimpleClientHttpRequestFactory {

	public BasicSecureSimpleClientHttpRequestFactory() {
	}

	@Override
	protected void prepareSecureConnection(HttpURLConnection connection) {
		if (credentialsProvider==null) {
			return;
		}
		Credentials credentials = credentialsProvider.getCredentials(AuthScope.ANY);
	    String token = credentials.getUserPrincipal() + ":" + credentials.getPassword();
		
		
	    String encodedAuthorization = org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(token.getBytes());
		//String encodedAuthorization = enc.encode(token.getBytes());
	    connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
	    
//	    URL url = new URL("http://www.example.com/comment");
//	    HttpURLConnection connection1 = (HttpURLConnection) url.openConnection();
//	    connection1.setRequestProperty("Authorization",
//	    "Basic "+ codec.encodeBase64String(("username:password").getBytes());
	}

	
}
